package com.cloudptt.api.product.operator;

import java.util.List;

import com.cloudptt.api.product.func.SipOperator;
import com.cloudptt.api.product.func.addr.IAddrDefaultOp;
import com.mcptt.config.local.SysConfig;
import com.mcptt.config.model.McIdInfo;
import com.mcptt.db.DBAdapter;
import com.mcptt.db.loader.address.MembListLoader;
import com.mcptt.db.loader.address.MembListLoaderCb;
import com.mcptt.db.model.AddrInfo;
import com.mcptt.db.model.GroupInfo;
import com.mcptt.db.model.GroupMembInfo;
import com.mcptt.db.model.MapPointInfo;
import com.mcptt.db.model.UserInfo;
import com.mcptt.http.operator.IHttpAddrOpCb;
import com.mcptt.http.operator.addr.AddressLoader;
import com.mcptt.http.operator.online.OnlineLoader;

import android.content.Context;

public class AddrOperator extends SipOperator
{
	private DBAdapter dbOperator = null;
	private IAddrDefaultOp defaultOp = null;
	private McIdInfo mcId = null;

	public AddrOperator(Context ctx, DBAdapter dbOperator, IAddrDefaultOp defaultOp, McIdInfo mcId)
	{
		super(ctx);
		this.dbOperator = dbOperator;
		this.defaultOp = defaultOp;
		this.mcId = mcId;
	}

	//	public void setUid(String uid) {
	//		this.uid = uid;
	//	}
	//	public void setCurGroupInfo(GroupInfo curGroupInfo) 
	//	{
	//		this.curGroupInfo = curGroupInfo;
	//	}
	public void loadAddressAndOnline(SysConfig config,final IHttpAddrOpCb callback)
	{
		AddressLoader loader = new AddressLoader(config,dbOperator,callback,defaultOp);
		loader.load();

//		OnlineLoader loader2 = new OnlineLoader(svrIp,dbOperator.getMapDbOperator(),callback);
//		loader2.load();
	}

	public void loadAddress(SysConfig config,final IHttpAddrOpCb callback)
	{
		AddressLoader loader = new AddressLoader(config,dbOperator,callback,defaultOp);
		loader.load();
	}

	public void loadOnlineState(final String svrIp,final IHttpAddrOpCb callback)
	{
		OnlineLoader loader = new OnlineLoader(svrIp,dbOperator,callback);
		loader.load();
	}
	public List<GroupInfo> getGroupList()
	{
		return dbOperator.getGroupInfoList();
	}
	public List<AddrInfo> getAddrInfoList() {
		return dbOperator.getAddrInfoList();
	}
	public List<AddrInfo> getAddrInfoList(boolean isGroup) {
		return dbOperator.getAddrInfoList(isGroup);
	}
//	public List<GroupInfo> getGroupListAndUserList()
//	{
//		return dbOperator.getGroupListAndUserList();
//	}
//	public void setDefaultGroupInfo(GroupInfo info)
//	{
//		AddressDbOperator db = dbOperator.getAddressDbOperator();
//		db.clearDefaultGroupInfo();
//		db.setDefaultGroupInfo(info);
//	}

	public List<UserInfo> getUserInfoList()
	{
		return dbOperator.getUserInfoList();
	}

	public List<MapPointInfo> getMapPointInfoList()
	{
		return dbOperator.getMapPointInfoList();
	}



	//	public void deleteUser(UserInfo info)
	//	{
	//		dbOperator.getAddressDbOperator().deleteUser(info);
	//	}

	//	private void addUser(UserInfo info)
	//	{
	//		dbOperator.getAddressDbOperator().addUser(info);
	//	}

	//	public AddressListLoader getAddressListLoader(Context ctx,int addrType,AddressListLoaderCb callback)
	//	{
	//		return new AddressListLoader(ctx,addrType,callback);
	//	}

	public List<UserInfo> getNewAddressList(String groupMcId){
		return dbOperator.getUserInfoList(groupMcId);
	}

	public void updateUserInfo(UserInfo info){
		dbOperator.updateUserInfo(info);
	}

	public List<UserInfo> getNewAddressList(String groupId,String mcId){
		return dbOperator.getUserInfoList(groupId);
	}
//	public LoginStateListLoader getLoginStateListLoader(Context ctx, LoginStateListLoaderCb callback){
//		return new LoginStateListLoader(ctx,dbOperator, callback);
//	}
//

	public MembListLoader getMembListLoader(Context ctx,UserInfo info,MembListLoaderCb callback)
	{
		return new MembListLoader(ctx,info,callback);
	}

	public List<GroupMembInfo> getGroupMemberList(AddrInfo info,String selfAddrId)
	{
		return dbOperator.getGroupMembInfoList(info,selfAddrId);
	}

//	public boolean isGrpHasMem(String uid)
//	{
//		return dbOperator.getGroupMembsDbOperator().isGrpHasMem(uid);
//	}


	//	public void sendGroupMembInfoMsg() throws RemoteException
	//	{
	//		Log.d(THIS_FILE, "sendGroupMembInfoMsg");
	//		if( curGroupInfo != null)
	//		{
	//			Log.d(THIS_FILE, "sendGroupMembInfoMsg curGroupInfo = " + curGroupInfo);
	//			sendGroupMembInfoMsg(curGroupInfo);
	//		}
	//	}
	//
	//	public void sendGroupMembStatusMsg(int opType) throws RemoteException
	//	{
	//		Log.d(THIS_FILE, "sendGroupMembStatusMsg opType = " + opType);
	//		if( curGroupInfo != null)
	//		{
	//			Log.d(THIS_FILE, "sendGroupMembStatusMsg curGroupInfo = " + curGroupInfo + " opType = " + opType);
	//			sendGroupMembStatusMsg(curGroupInfo,opType);
	//		}
	//		
	////		if(opType == GroupMembInfo.QueryMembStatus_Begin)
	////		{
	////			dbOperator.getGroupMembsDbOperator().resetGrpMemCallState();
	////		}
	//		
	//		dbOperator.getGroupMembsDbOperator().resetGrpMemCallState();
	//	}
//	public void resetGrpMemCallState()
//	{
//		dbOperator.getGroupMembsDbOperator().resetGrpMemCallState();
//	}
//
//	public List<CameraInfo> getCameraList()
//	{
//		return dbOperator.getCameraDbOperator().getCameraList();
//	}
//
//	public void addCameraInfo(CameraInfo info)
//	{
//		dbOperator.getCameraDbOperator().addCameraInfo(info);
//	}
//
//	public CameraInfo findCameraInfoByIp(String ip)
//	{
//		return dbOperator.getCameraDbOperator().findCameraInfoByIp(ip);
//	}
//
//	public void deleteCameraInfo(CameraInfo info)
//	{
//		dbOperator.getCameraDbOperator().deleteCameraInfo(info);
//	}
}
